package com.fishingwithme.android.ui.screens.my

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import com.fishingwithme.android.R
import com.fishingwithme.android.data.model.UserCredit
import com.fishingwithme.android.ui.theme.AppDimensions
import com.fishingwithme.android.ui.theme.LVL_ICONS


@Composable
fun CreditHeaderSection(creditData: UserCredit) {
    Card(
        modifier = Modifier.fillMaxWidth(),
        shape = RoundedCornerShape(AppDimensions.ROUNDED_CORNER_12),
        colors = CardDefaults.cardColors(
            containerColor = MaterialTheme.colorScheme.primaryContainer
        )
    ) {
        Column(
            modifier = Modifier
                .fillMaxWidth()
                .padding(AppDimensions.SPACING_16),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {
            val badgeResId = LVL_ICONS[creditData.currentLevel] ?: R.mipmap.lvl_11
            Icon(

                painter = painterResource(id = badgeResId),
                contentDescription = "Level Badge",
                modifier = Modifier
                    .size(AppDimensions.ICON_SIZE_120)
                    .clip(shape = RoundedCornerShape(AppDimensions.ROUNDED_CORNER_50)),
                tint = Color.Unspecified,

                )

            Spacer(modifier = Modifier.height(AppDimensions.SPACING_8))

            Text(
                text = "${creditData.currentLevelName} (Lv.${creditData.currentLevel})",
                style = MaterialTheme.typography.headlineSmall,
                color = MaterialTheme.colorScheme.onPrimaryContainer,
                fontWeight = FontWeight.Bold
            )

            Spacer(modifier = Modifier.height(AppDimensions.SPACING_16))

            Text(
                text = stringResource(R.string.credit_total_points),
                style = MaterialTheme.typography.bodyMedium,
                color = MaterialTheme.colorScheme.onPrimaryContainer
            )

            Spacer(modifier = Modifier.height(AppDimensions.SPACING_4))

            Text(
                text = creditData.totalPoints.toString(),
                style = MaterialTheme.typography.displaySmall,
                color = MaterialTheme.colorScheme.onPrimaryContainer,
                fontWeight = FontWeight.Bold
            )
        }
    }
}
